package com.dst.controller;

import com.dst.dao.BrandDao;
import com.dst.dao.impl.BrandDaoimpl;
import com.dst.eneity.Phone;
import com.dst.service.BrandService;
import com.dst.service.PhoneService;
import com.dst.service.impl.BrandServiceImpl;
import com.dst.service.impl.PhoneServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/brand/deleteByIdBrandController")
public class DeleteByIdBrandController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id = Integer.parseInt(req.getParameter("id"));
        BrandService brandService = new BrandServiceImpl();
        brandService.deleteByIdBrandService(id);
        PhoneService phoneService = new PhoneServiceImpl();
        List<Phone> select = phoneService.select(id);
        int [] id1=new int [select.size()];
        for (int i = 0; i <select.size() ; i++) {
            id1[i]=select.get(i).getId();
        }
        phoneService.batchDeleteService(id1);
        resp.sendRedirect(req.getContextPath()+"/brand/selectAllBrandController");
    }
}
